/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file    cordic.c
 * @brief   This file provides code for the configuration
 *          of the CORDIC instances.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2025 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "cordic.h"

/* USER CODE BEGIN 0 */
CORDIC_ConfigTypeDef CORDIC_Config;
/* USER CODE END 0 */

CORDIC_HandleTypeDef hcordic;

/* CORDIC init function */
void MX_CORDIC_Init(void)
{

  /* USER CODE BEGIN CORDIC_Init 0 */

  /* USER CODE END CORDIC_Init 0 */

  /* USER CODE BEGIN CORDIC_Init 1 */

  /* USER CODE END CORDIC_Init 1 */
  hcordic.Instance = CORDIC;
  if (HAL_CORDIC_Init(&hcordic) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN CORDIC_Init 2 */
    CORDIC_Config.Function = CORDIC_FUNCTION_SINE;       // 计算模式为sin
    CORDIC_Config.Precision = CORDIC_PRECISION_6CYCLES;  // 迭代6次
    CORDIC_Config.Scale = CORDIC_SCALE_0;                // 缩放因子，0为原始值，1为原始/2
    CORDIC_Config.NbWrite = CORDIC_NBWRITE_1;            // 传入个数（1：角度，2：xy坐标）
    CORDIC_Config.NbRead = CORDIC_NBREAD_1;              // 读出数据个数（此处写2可以读sin+cos）
    CORDIC_Config.InSize = CORDIC_INSIZE_32BITS;         // 输入格式：Q1.31
    CORDIC_Config.OutSize = CORDIC_OUTSIZE_32BITS;       // 输出格式：Q1.31
    HAL_CORDIC_Configure(&hcordic, &CORDIC_Config);      // 更新CORDIC参数
  /* USER CODE END CORDIC_Init 2 */

}

void HAL_CORDIC_MspInit(CORDIC_HandleTypeDef* cordicHandle)
{

  if(cordicHandle->Instance==CORDIC)
  {
  /* USER CODE BEGIN CORDIC_MspInit 0 */

  /* USER CODE END CORDIC_MspInit 0 */
    /* CORDIC clock enable */
    __HAL_RCC_CORDIC_CLK_ENABLE();
  /* USER CODE BEGIN CORDIC_MspInit 1 */

  /* USER CODE END CORDIC_MspInit 1 */
  }
}

void HAL_CORDIC_MspDeInit(CORDIC_HandleTypeDef* cordicHandle)
{

  if(cordicHandle->Instance==CORDIC)
  {
  /* USER CODE BEGIN CORDIC_MspDeInit 0 */

  /* USER CODE END CORDIC_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_CORDIC_CLK_DISABLE();
  /* USER CODE BEGIN CORDIC_MspDeInit 1 */

  /* USER CODE END CORDIC_MspDeInit 1 */
  }
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
